home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / VideoToolboxSources / CommandPeriod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  3.5 KB  |  95 lines  |  [TEXT/CWIE]

  1. /*
  2. CommandPeriod.c
  3.  
  4. Checks the event queue and returns 1 if user typed Command-period.
  5. This uses the System call IsCmdChar() to recognize Command-period,
  6. which is supposed to work even on international keyboards.
  7.  
  8. If there are other unprocessed key presses ahead of the command-period key press
  9. then we won't detect the command-period until they've been removed from the queue. 
  10. We only examine the key press that's at the top of the queue.
  11.  
  12. HISTORY:
  13. 3/97    dgp wrote it.
  14. 3/19/97    dgp David Brainard noticed that we were treating plain period as equivalent to command-period.
  15.                         It turns out that I hadn't read the documentation for IsCmdChar() carefully enough. It
  16.                         doesn't check for the Command key, so I've added an explicit test for the command key.
  17.                         Now allow for an "autoKey" as well as a "keyDown" event.
  18. 4/10/97    dgp    Eliminate stuff that was conditional on !UNIVERSAL_HEADERS.
  19.  
  20. NOTES:
  21. http://devworld.apple.com/dev/techsupport/develop/issue22/macqa.html
  22. http://devworld.apple.com/dev/technotes/te/te_23.html
  23.  
  24. The following is copied from Apple's develop 22 Q&A (June 1996). As of January 1997 this is still
  25. the only documentation that Apple has provided for this function, despite claims to
  26. have added it to the Macintosh Technical Note "International Canceling" (TE 23). 
  27.  
  28. extern pascal Boolean IsCmdChar(const EventRecord *event, short test);
  29.  
  30. This function tests whether the Command key is being pressed in conjunction with another key (or
  31. keys) that could generate testChar for some combination of Command up or down and Shift up or
  32. down. This accommodates European keyboards that may have testChar as a shifted character, and
  33. non-Roman keyboards that will only generate testChar if Command is down. It's most useful for
  34. testing for Command-period.
  35.  
  36. The caller passes in the event record, which is assumed by the function to be an event record for a
  37. key-down or auto-key event with the Command key down. The caller also passes in the character to
  38. be tested for (for example, '.'). The function returns TRUE if testChar is produced with the current
  39. modifier keys, or if it would be produced by changing the current modifier key bits in either or both
  40. of the following ways: 
  41.  
  42.        turning the Command bit off 
  43.  
  44.        toggling the Shift bit
  45.  
  46. "That routine was introduced with System 7." [To test for availability, just check for System 7.]
  47. */
  48. #include "VideoToolbox.h"
  49. // IsCmdChar() documented in develop 22 Q&A.
  50. #ifndef __SCRIPT__
  51.     #include <Script.h>    // IsCmdChar
  52. #endif
  53.  
  54. Boolean CommandPeriod(void)
  55. {
  56.     static Boolean firstTime=1;
  57.     long version;
  58.     EventRecord event;
  59.     
  60.     if(firstTime){
  61.         // Make sure IsCmdChar() trap is available.
  62.         Gestalt(gestaltSystemVersion,&version);
  63.         if(version<0x700)PrintfExit("%s: require System 7.\n",__FILE__);
  64.         firstTime=0;
  65.     }
  66.     if(EventAvail(keyDownMask|autoKeyMask,&event) && IsCmdChar(&event,'.') && (event.modifiers & cmdKey)){
  67.         GetNextEvent(keyDownMask|autoKeyMask,&event);    // consume the event.
  68.         return 1;
  69.     }else return 0;    
  70. }
  71.  
  72. short GetNextEventOrQuit(int mask,EventRecord *eventPtr)
  73. {
  74.     if(CommandPeriod()){
  75.         #if MATLAB
  76.             PrintfExit("User typed cmd-. EXITING.");
  77.         #else
  78.             PrintfExit("\nUser typed cmd-. EXITING.\n");
  79.         #endif
  80.     }
  81.     return GetNextEvent(mask,eventPtr);
  82. }
  83.  
  84. Boolean WaitNextEventOrQuit(int mask,EventRecord *eventPtr,unsigned long sleep,RgnHandle mouseRgn)
  85. {
  86.     if(CommandPeriod()){
  87.         #if MATLAB
  88.             PrintfExit("User typed cmd-. EXITING.");
  89.         #else
  90.             PrintfExit("\nUser typed cmd-. EXITING.\n");
  91.         #endif
  92.     }
  93.     return WaitNextEvent(mask,eventPtr,sleep,mouseRgn);
  94. }
  95.